//
//  demoViewController.m
//  iOS_Router_Runtime
//
//  Created by 王水鑫 on 2018/11/8.
//  Copyright © 2018年 王水鑫. All rights reserved.
//

#import "demoViewController.h"

@interface demoViewController ()

@end

@implementation demoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //优先级 Silca > Ilco > keyline > JMA 按manufacturer的value
    NSArray * target = @[@{@"manufacturer":@"JMA",@"name":@"KK10-P"}, @{@"manufacturer":@"keyline",@"name":@"KK10-P"}, @{@"manufacturer":@"Ilco",@"name":@"KK10-P"}, @{@"manufacturer":@"Ilco",@"name":@"LXP90-P"}, @{@"manufacturer":@"Silca",@"name":@"KIA7T14"}, @{@"manufacturer":@"Silca",@"name":@"TOY40"}, @{@"manufacturer":@"Silca",@"name":@"TOY49MH"}, @{@"manufacturer":@"Ilco",@"name":@"KK10-P"}];
    NSLog(@"需要整理数据的数组:%@", target);
    NSLog(@"排序后的数组：%@", [self sortedByCustomRulesWithArray:target]);
}
- (NSArray *)sortedByCustomRulesWithArray:(NSArray *)array {
    NSMutableArray *Silca_MArray = [NSMutableArray array];
    NSMutableArray *ilco_MArray = [NSMutableArray array];
    NSMutableArray *keyline_MArray = [NSMutableArray array];
    NSMutableArray *JMA_MArray = [NSMutableArray array];
    for (NSDictionary *dict in array) {
        if ([dict[@"manufacturer"] isEqualToString:@"Silca"]) {
            
            [Silca_MArray addObject:dict];
        } else if ([dict[@"manufacturer"] isEqualToString:@"Ilco"]) {
        
            [ilco_MArray addObject:dict];
        }else if ([dict[@"manufacturer"] isEqualToString:@"keyline"]) {
            
            [keyline_MArray addObject:dict];
        }else if ([dict[@"manufacturer"] isEqualToString:@"JMA"]) {
            
            [JMA_MArray addObject:dict];
        }
    }
    //按优先级 Silca > Ilco > keyline > JMA组装数组
    NSMutableArray *resultArray = [NSMutableArray array];
    [resultArray addObjectsFromArray:Silca_MArray];
    [resultArray addObjectsFromArray:ilco_MArray];
    [resultArray addObjectsFromArray:keyline_MArray];
    [resultArray addObjectsFromArray:JMA_MArray];
    NSLog(@"看组装数组是否满足要求:%@", resultArray);
    return resultArray;
}


@end
